package model.util.stats;
//AMLOW: use or delete.
//package model.stats;
//
//public class CorrelationCalculation {
//
//	
//	public double getCorrelationCoefficient(double[] market, 
//													double[] model){
//		
//		if(market.length!=model.length){
//			throw new RuntimeException("WTF! different length arrays, bitch!");
//		}
//		
//		//we need sum of x values.
//		double marketSum =0;
//		
//		//and sum of y values
//		double modelSum =0;
//		
//		//and sum of x * y values..
//		double crossMultiple= 0;
//		
//		//and sum of x squared values
//		double marketSquared =0;
//		
//		//and sum of y squared values.
//		double modelSquared =0;
//		
//		for(int i=0;i<market.length;i++){
//			double marketValue = market[i];
//			double modelValue = model[i];
//			
//			marketSum+=marketValue;
//			modelSum+=modelValue;
//			crossMultiple+=marketValue*modelValue;
//			marketSquared+=marketValue*marketValue;
//			modelSquared+=modelValue*modelValue;
//		}
//		
//		double modelSumSquared = modelSum*modelSum;
//		double marketSumSquared = marketSum*marketSum;
//		
//		double stdDevMarket= Math.sqrt((marketSquared-(marketSumSquared/market.length))/(market.length-1));
//		double stdDevModel= Math.sqrt((modelSquared-(modelSumSquared/market.length))/(market.length-1));
//		
//		if(stdDevModel==0){
//			//we got a constant
//			return 0;
//			
//		}
//		
//		double correlation = (crossMultiple-(modelSum*marketSum/market.length))
//								/((market.length-1)*stdDevMarket*stdDevModel);
//		
//		if(correlation>1||correlation<-1){
//			System.out.println("Variables: modelSumSquared: "+modelSumSquared+
//									" market sum squared: "+marketSumSquared+
//									"\n stdDevMarket: "+stdDevMarket+
//									" stdDEvModel: "+stdDevModel+
//									" crossMultiple "+crossMultiple);
//			System.out.println("model prices:");
//			for(int i=0;i<model.length;i++){
//				System.out.print(", "+model[i]);
//			}
//			
//			System.out.println();
//			throw new RuntimeException("correlation calc is fu*ked: "+correlation);
//		}
//		return correlation;
//		
//	}
//	
//	
//	
//	
//	
//}
